package com.example.design.leetcode;

/**
 * @Description 删除排序数组中的重复项
 * @date 2023/9/18 17:14
 * @Author liuzhihui
 * @Version 1.0
 */

// 思路：双指针。
// slow指针从0开始, fast指针从1开始。不相等,slow和fast指针都后移一位，相等，
public class SortedArrayDuplicates {
    public static void main(String[] args) {

        System.out.println(removeDuplicates(new int[] {0,1,2,2,3,3,4}));
    }


    public static int removeDuplicates(int[] arrays){
        if (arrays.length == 0) {
            return 0;
        }
        int slow = 0;
        for (int fast = 1; fast < arrays.length; fast++) {
            if (arrays[fast] != arrays[slow]) {
                slow++;
            } else {
                arrays[slow+1] = arrays[fast];
            }
        }
        return slow;
    }

}
